package com.co.model.bean.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.co.model.bean.Prestacion;
import com.co.persistence.HibernateUtils;

public class HibernateDao {
	private static HibernateDao instancia = null;
	private static SessionFactory sf = null;

	public static HibernateDao getInstancia() {
		if (instancia == null) {
			sf = HibernateUtils.getSessionFactory();
			instancia = new HibernateDao();
		}
		return instancia;
	}

	public void saveObjeto(Object objeto) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(objeto);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public Prestacion getPrestacion(String codigo) {
		Session s = sf.openSession();
		Prestacion p = (Prestacion) s
				.createQuery("select P from Prestacion P where P.codigo = :cod")
				.setParameter("cod", codigo).uniqueResult();
		return p;
	}
}